package com.xing.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/12/5 13:08
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result implements Serializable {
    private Integer code;
    private Object data;
    private String msg;

    static Result result = new Result();
    public Result ok(Object data){
        result.setCode(Code.SUCCESS_ID.ordinal());
        result.setData(data);
        result.setMsg("SUCCESS");
        return result;
    }

    public Result ok(){
        result.setCode(Code.SUCCESS_ID.ordinal());
        result.setMsg("SUCCESS");
        return result;
    }

    public Result err(Integer code, String msg){
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public Result err(Integer code){
        result.setCode(code);
        result.setMsg("ERROR");
        return result;
    }
}


